package es.mahulo.battleship.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 * Ship represent a list of cells in the board. There are five different types
 * of ships, the only difference is the number of cell the uses. 
 * 
 * @author mhuertas
 *
 */
@XmlRootElement
@Entity
@Table(name="SHIP")
public class Ship {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name="ID")
	private Long id;

	/**
	 * List of the cell for this Ship.
	 */
	@OneToMany(targetEntity=Cell.class,mappedBy="ship",fetch=FetchType.EAGER,cascade = {CascadeType.ALL })
	private List<Cell> cells;
	
	@ManyToOne
	@JoinColumn(name="ID_PLAYER")	
	private Player player;

	@OneToOne(cascade = {CascadeType.PERSIST })
	@JoinColumn(name="ID_SHIP_CONFIG") 
	private ShipConfig shipConfig;

	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public List<Cell> getCells() {
		return cells;
	}

	public void setCells(List<Cell> cells) {
		this.cells = cells;
	}

	@XmlTransient
	public Player getPlayer() {
		return player;
	}

	public void setPlayer(Player player) {
		this.player = player;
	}
	
	
	public ShipConfig getShipConfig() {
		return shipConfig;
	}

	public void setShipConfig(ShipConfig shipConfig) {
		this.shipConfig = shipConfig;
	}

	public String toString() {
		return "Ship { Id: "
				+ id 
				+ " player: " 
				+ player 
				+ " cells: " 
				+ cells
				+ " shipConfig: "
				+ shipConfig 
				+ " } "; 
	}
}


